///首页对象，待扩展
var shopIndex = {
};

$(function(){
    shopIndex.init();
});
shopIndex.init=function(){
    //tab标签页
    this.methods.tabInit(this);
    //热销榜
    this.methods.hotInit(this);
    //滚动初始化
    this.methods.SliderInit(this);
    //倒计时
    shopIndex.methods.RunTimer(this);
    //轮播组件
    this.methods.bannerInit(this);
    // 新增两个模板的四个轮播组件初始化
    this.methods.wheelInit(this);
    //定位
    // shopIndex.methods.getLocation(this);
};
shopIndex.addEvent=function(){ 
    //事件管理
};
shopIndex.methods = {};
shopIndex.data={};

//轮播组件
shopIndex.methods.bannerInit=function(obj){
    $(".shop-fullSlide").slide({ 
        titCell:".shop-hd ul", 
        mainCell:".shop-bd ul", 
        effect:"leftLoop", 
        vis:"auto", 
        autoPlay:true, 
        autoPage:true, 
        trigger:"click"
    });
}
// 新增两个模板的四个轮播组件初始化
shopIndex.methods.wheelInit = function(){
    // 排行榜
    //标题切换，只切换targetCell
	$(".shop-book-list").slide({ 
        titCell:".shop-book-list-smallTitle a",
        targetCell:".book-list-con",
        delayTime:0 ,
        defaultIndex:0
    });
	//小圆点左切换
	$(".book-list-con").slide({ 
        titCell:".shop-book-dot-con li",
        mainCell:".shop-book-list-wheel",
        effect:"left",
        autoPlay: false,
        //autoPage: true,
        trigger:"mouseover",
        defaultIndex:0
    });


    // 会买专辑
    $(".shop-book-buy").slide({
        titCell: ".shop-book-dot ul",
        mainCell: ".shop-book-buy-con .shop-book-buy-wheel",
        effect: "leftLoop",
        autoPlay: true,
        autoPage: true,
        trigger: "mouseover",
    });
    
    // 领券中心
    $(".shop-book-vou").slide({
        titCell: ".shop-book-dot ul",
        mainCell: ".shop-book-vou-con .shop-book-vou-wheel",
        effect: "leftLoop",
        autoPlay: false,
        autoPage: true,
        trigger: "mouseover"
    });
 
    // 觅me
    $(".shop-book-me").slide({
        titCell: ".shop-book-dot ul",
        mainCell: ".shop-book-me-con .shop-book-me-wheel",
        effect: "leftLoop",
        autoPlay: true,
        autoPage: true,
        trigger: "mouseover"
    });
    $(".shop-book-dot-con ul li").text("");

}


//tab组件初始化方法
shopIndex.methods.tabInit = function(obj){
    $(".shop-floor").each(function(val){
        if($(this).find(".shop-floor-nav")){
            //有tab，添加tab控件
            var tab = new Controller.TabControl({
                container:$(this),
                tabNavItem:".shop-floor-nav-item",
                tabConItem:".shop-floor-container",
                tagName:"data-id",
                event:"mouseover"
            });
        }
    });
    var hottab = new Controller.TabControl({
        container:$(".shop-hot-sell"),
        tabNavItem:".shop-floor-nav-item",
        tabConItem:".shop-rank-container-right",
        tagName:"data-id",
        event:"mouseover"
    });
}
shopIndex.methods.hotInit =function(obj){
    $(".shop-rank-container .shop-rank-container-right li").off("mouseover").on("mouseover",function(){
        $(this).siblings("li").removeClass("bigli").removeClass("normalli").addClass("normalli");
        $(this).removeClass("normalli");
        $(this).addClass("bigli");
    });
}
shopIndex.methods.SliderInit=function(obj){
    var slider = new Controller.Slider({
        father: ".shop-flash-right",
        container:"ul",
        prevBtn: ".shop-flash-left-nav",
        nextBtn: ".shop-flash-right-nav",
        itemSelector: "li",
        fatherSize: 1148
    });
}
shopIndex.methods.RunTimer = function(obj){
	var allsecond = 3602; //总计秒数
    		
    		function AddZero(num){
    			return num<10?'0'+num:num;
    		}
    		
    		var timer=setInterval(function(){ 
    			if(allsecond>=0){
		      	 //小时
		        var h  = parseInt(allsecond/3600); 
		      	 //分钟
		        var m  = parseInt(allsecond%3600/60);
		      	 //秒数
		        var s  = allsecond%3600%60;
		        var nexth = parseInt((allsecond-1)/3600);
		        var nextm = parseInt((allsecond-1)%3600/60);
		        var nexts =  s-1;
		        //初始化值
		        $(".shop-flash-clocking>ul>li").each(function(n,e){
		        	// console.log(n);
		        	if(n == 0)
		        	{
		        		//分钟滚动
		        		$(e).find("span").first().html(AddZero(h));
		        		$(e).find("span").last().html(AddZero(h));
		        	}
		        	else if(n==1)
		        	{
		        		//分钟滚动
		        		$(e).find("span").first().html(AddZero(m));
		        		$(e).find("span").last().html(AddZero(m));
		        	}
		        	else
		        	{
		        		//秒钟滚动
		        		$(e).find("span").first().html(AddZero(s));
		        		$(e).find("span").last().html(AddZero(s));
			        	//开始滚动
			        	$(e).find("span").first().animate({'margin-top':'-40px'},200);
			        	$(e).find("span").first().animate({'margin-top':'0px'},0);
		        	}
		        });
		        
		       // console.log(allsecond);
		        allsecond = allsecond-1;
		      }else{
		        clearInterval(timer);
		      }
		    },1000);
}

// 定位
shopIndex.methods.getLocation = function (obj) {
    var locationStr = returnCitySN.cname;
    $(".shop-position .shop-position-title").html("<span></span>" + "&nbsp;&nbsp;&nbsp;" + locationStr.substring(3));
    
}
